package Window;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import javax.swing.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;

public class mod extends JFrame{
    public mod(){
        setSize(300,290);
        setVisible(true);
        JLabel a=new JLabel("名称"); //实例化JLabel对象
        JLabel b=new JLabel("编号");
        JLabel c=new JLabel("简介");
    //    JLabel h=new JLabel("结点");

        JTextField d=new JTextField(15);
        JTextField e=new JTextField(15);
        JTextField f=new JTextField(30);
    //    JTextField i=new JTextField(15);

        JButton g=new JButton("确定");

        Container mk=getContentPane();

        mk.add(a);
        mk.add(b);
        mk.add(c);
        mk.add(d);
        mk.add(e);
        mk.add(f);
        mk.add(g);
     //   mk.add(h);
     //   mk.add(i);

        setBounds(300,300,300,290);//设置窗体的长宽各为300、300  让其显示在左上方的300、300处
        mk.setLayout(null);

        a.setBounds(10,40,50,18);
        b.setBounds(10,60,50,18);
        c.setBounds(10,80,50,18);
        d.setBounds(60,40,200,18);
        e.setBounds(60,60,200,18);
        f.setBounds(60,80,200,18);
        g.setBounds(110,180,60,30);
    //    h.setBounds(10,20,50,18);
    //    i.setBounds(60,20,200,18);

        g.addActionListener(new ActionListener() {//对查看按钮添加监听事件
            public void actionPerformed(ActionEvent arg0) {
                if (d.getText().trim().equals("三国公园")) {
                    // TODO Auto-generated method stub
                    File file = new File("D:\\GitHOME\\information\\text.xml");
                    DocumentBuilder newDocumentBuilder = null;
                    try {
                        newDocumentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                    } catch (ParserConfigurationException e) {
                        e.printStackTrace();
                    }
                    Document doc = null;
                    try {
                        doc = newDocumentBuilder.parse(file);
                    } catch (SAXException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    Element root = doc.getDocumentElement();
                    //查找指定节点
                    //通过根节点获得子节点
                    NodeList personList = root.getElementsByTagName("spot");
                    Node item = personList.item(0);
                    Element personElement = (Element) item;
                    //personElement.
                    NodeList idList = personElement.getElementsByTagName("id");
                    //修改
                    String h = e.getText();
                    idList.item(0).setTextContent(h);
                    NodeList introList = personElement.getElementsByTagName("intro");
                    String i = f.getText();
                    introList.item(0).setTextContent(i);
                    Transformer transformer = null;
                    try {
                        transformer = TransformerFactory.newInstance().newTransformer();
                    } catch (TransformerConfigurationException e) {
                        e.printStackTrace();
                    }
                    Source source = new DOMSource(doc);
                    Result result = new StreamResult(file);
                    try {
                        transformer.transform(source, result);
                    } catch (TransformerException e) {
                        e.printStackTrace();
                    }
                }
                if (d.getText().trim().equals("荆州博物馆")){
                    File file = new File("D:\\GitHOME\\information\\text.xml");
                    DocumentBuilder newDocumentBuilder = null;
                    try {
                        newDocumentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                    } catch (ParserConfigurationException e) {
                        e.printStackTrace();
                    }
                    Document doc = null;
                    try {
                        doc = newDocumentBuilder.parse(file);
                    } catch (SAXException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    Element root = doc.getDocumentElement();
                    //查找指定节点
                    //通过根节点获得子节点
                    NodeList personList = root.getElementsByTagName("spot");
                    Node item = personList.item(1);
                    Element personElement = (Element) item;
                    //personElement.
                    NodeList idList = personElement.getElementsByTagName("id");
                    //修改
                    String h = e.getText();
                    idList.item(0).setTextContent(h);
                    NodeList introList = personElement.getElementsByTagName("intro");
                    String i = f.getText();
                    introList.item(0).setTextContent(i);
                    Transformer transformer = null;
                    try {
                        transformer = TransformerFactory.newInstance().newTransformer();
                    } catch (TransformerConfigurationException e) {
                        e.printStackTrace();
                    }
                    Source source = new DOMSource(doc);
                    Result result = new StreamResult(file);
                    try {
                        transformer.transform(source, result);
                    } catch (TransformerException e) {
                        e.printStackTrace();
                    }
                }
                if (d.getText().trim().equals("九老仙都景区")){
                    File file = new File("D:\\GitHOME\\information\\text.xml");
                    DocumentBuilder newDocumentBuilder = null;
                    try {
                        newDocumentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                    } catch (ParserConfigurationException e) {
                        e.printStackTrace();
                    }
                    Document doc = null;
                    try {
                        doc = newDocumentBuilder.parse(file);
                    } catch (SAXException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    Element root = doc.getDocumentElement();
                    //查找指定节点
                    //通过根节点获得子节点
                    NodeList personList = root.getElementsByTagName("spot");
                    Node item = personList.item(2);
                    Element personElement = (Element) item;
                    //personElement.
                    NodeList idList = personElement.getElementsByTagName("id");
                    //修改
                    String h = e.getText();
                    idList.item(0).setTextContent(h);
                    NodeList introList = personElement.getElementsByTagName("intro");
                    String i = f.getText();
                    introList.item(0).setTextContent(i);
                    Transformer transformer = null;
                    try {
                        transformer = TransformerFactory.newInstance().newTransformer();
                    } catch (TransformerConfigurationException e) {
                        e.printStackTrace();
                    }
                    Source source = new DOMSource(doc);
                    Result result = new StreamResult(file);
                    try {
                        transformer.transform(source, result);
                    } catch (TransformerException e) {
                        e.printStackTrace();
                    }
                }
                if (d.getText().trim().equals("荆州盆景区")){
                    File file = new File("D:\\GitHOME\\information\\text.xml");
                    DocumentBuilder newDocumentBuilder = null;
                    try {
                        newDocumentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                    } catch (ParserConfigurationException e) {
                        e.printStackTrace();
                    }
                    Document doc = null;
                    try {
                        doc = newDocumentBuilder.parse(file);
                    } catch (SAXException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    Element root = doc.getDocumentElement();
                    //查找指定节点
                    //通过根节点获得子节点
                    NodeList personList = root.getElementsByTagName("spot");
                    Node item = personList.item(3);
                    Element personElement = (Element) item;
                    //personElement.
                    NodeList idList = personElement.getElementsByTagName("id");
                    //修改
                    String h = e.getText();
                    idList.item(0).setTextContent(h);
                    NodeList introList = personElement.getElementsByTagName("intro");
                    String i = f.getText();
                    introList.item(0).setTextContent(i);
                    Transformer transformer = null;
                    try {
                        transformer = TransformerFactory.newInstance().newTransformer();
                    } catch (TransformerConfigurationException e) {
                        e.printStackTrace();
                    }
                    Source source = new DOMSource(doc);
                    Result result = new StreamResult(file);
                    try {
                        transformer.transform(source, result);
                    } catch (TransformerException e) {
                        e.printStackTrace();
                    }
                }
                if (d.getText().trim().equals("关帝庙")){
                    File file = new File("D:\\GitHOME\\information\\text.xml");
                    DocumentBuilder newDocumentBuilder = null;
                    try {
                        newDocumentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                    } catch (ParserConfigurationException e) {
                        e.printStackTrace();
                    }
                    Document doc = null;
                    try {
                        doc = newDocumentBuilder.parse(file);
                    } catch (SAXException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    Element root = doc.getDocumentElement();
                    //查找指定节点
                    //通过根节点获得子节点
                    NodeList personList = root.getElementsByTagName("spot");
                    Node item = personList.item(4);
                    Element personElement = (Element) item;
                    //personElement.
                    NodeList idList = personElement.getElementsByTagName("id");
                    //修改
                    String h = e.getText();
                    idList.item(0).setTextContent(h);
                    NodeList introList = personElement.getElementsByTagName("intro");
                    String i = f.getText();
                    introList.item(0).setTextContent(i);
                    Transformer transformer = null;
                    try {
                        transformer = TransformerFactory.newInstance().newTransformer();
                    } catch (TransformerConfigurationException e) {
                        e.printStackTrace();
                    }
                    Source source = new DOMSource(doc);
                    Result result = new StreamResult(file);
                    try {
                        transformer.transform(source, result);
                    } catch (TransformerException e) {
                        e.printStackTrace();
                    }
                }
                if (d.getText().trim().equals("明月公园")){
                    File file = new File("D:\\GitHOME\\information\\text.xml");
                    DocumentBuilder newDocumentBuilder = null;
                    try {
                        newDocumentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                    } catch (ParserConfigurationException e) {
                        e.printStackTrace();
                    }
                    Document doc = null;
                    try {
                        doc = newDocumentBuilder.parse(file);
                    } catch (SAXException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    Element root = doc.getDocumentElement();
                    //查找指定节点
                    //通过根节点获得子节点
                    NodeList personList = root.getElementsByTagName("spot");
                    Node item = personList.item(5);
                    Element personElement = (Element) item;
                    //personElement.
                    NodeList idList = personElement.getElementsByTagName("id");
                    //修改
                    String h = e.getText();
                    idList.item(0).setTextContent(h);
                    NodeList introList = personElement.getElementsByTagName("intro");
                    String i = f.getText();
                    introList.item(0).setTextContent(i);
                    Transformer transformer = null;
                    try {
                        transformer = TransformerFactory.newInstance().newTransformer();
                    } catch (TransformerConfigurationException e) {
                        e.printStackTrace();
                    }
                    Source source = new DOMSource(doc);
                    Result result = new StreamResult(file);
                    try {
                        transformer.transform(source, result);
                    } catch (TransformerException e) {
                        e.printStackTrace();
                    }
                }
                if (d.getText().trim().equals("关公义园")){
                    File file = new File("D:\\GitHOME\\information\\text.xml");
                    DocumentBuilder newDocumentBuilder = null;
                    try {
                        newDocumentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                    } catch (ParserConfigurationException e) {
                        e.printStackTrace();
                    }
                    Document doc = null;
                    try {
                        doc = newDocumentBuilder.parse(file);
                    } catch (SAXException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    Element root = doc.getDocumentElement();
                    //查找指定节点
                    //通过根节点获得子节点
                    NodeList personList = root.getElementsByTagName("spot");
                    Node item = personList.item(6);
                    Element personElement = (Element) item;
                    //personElement.
                    NodeList idList = personElement.getElementsByTagName("id");
                    //修改
                    String h = e.getText();
                    idList.item(0).setTextContent(h);
                    NodeList introList = personElement.getElementsByTagName("intro");
                    String i = f.getText();
                    introList.item(0).setTextContent(i);
                    Transformer transformer = null;
                    try {
                        transformer = TransformerFactory.newInstance().newTransformer();
                    } catch (TransformerConfigurationException e) {
                        e.printStackTrace();
                    }
                    Source source = new DOMSource(doc);
                    Result result = new StreamResult(file);
                    try {
                        transformer.transform(source, result);
                    } catch (TransformerException e) {
                        e.printStackTrace();
                    }
                }
                if (d.getText().trim().equals("御河广场")){
                    File file = new File("D:\\GitHOME\\information\\text.xml");
                    DocumentBuilder newDocumentBuilder = null;
                    try {
                        newDocumentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                    } catch (ParserConfigurationException e) {
                        e.printStackTrace();
                    }
                    Document doc = null;
                    try {
                        doc = newDocumentBuilder.parse(file);
                    } catch (SAXException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    Element root = doc.getDocumentElement();
                    //查找指定节点
                    //通过根节点获得子节点
                    NodeList personList = root.getElementsByTagName("spot");
                    Node item = personList.item(7);
                    Element personElement = (Element) item;
                    //personElement.
                    NodeList idList = personElement.getElementsByTagName("id");
                    //修改
                    String h = e.getText();
                    idList.item(0).setTextContent(h);
                    NodeList introList = personElement.getElementsByTagName("intro");
                    String i = f.getText();
                    introList.item(0).setTextContent(i);
                    Transformer transformer = null;
                    try {
                        transformer = TransformerFactory.newInstance().newTransformer();
                    } catch (TransformerConfigurationException e) {
                        e.printStackTrace();
                    }
                    Source source = new DOMSource(doc);
                    Result result = new StreamResult(file);
                    try {
                        transformer.transform(source, result);
                    } catch (TransformerException e) {
                        e.printStackTrace();
                    }
                }
                }




        });
    }
    }
